package com.example.reader.controller;

import com.example.reader.common.Result;
import com.example.reader.entity.Book;
import com.example.reader.service.BookService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;



    //查询书籍信息
    @GetMapping("/selectAll")
    public Result selectAll(Book book){
        List<Book> list=bookService.selectAll(book);
        return Result.success(list);
    }
    @GetMapping("/selectPage")
    public Result selectPage(Book book,@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize){
        PageInfo pageInfo=bookService.selectPage(book,pageNum,pageSize);
        return Result.success(pageInfo);
    }

    //根据id查阅书籍详情
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id){
        Book book=bookService.selectById(id);
        return Result.success(book);
    }

}
